package com.ry.bhwktapp.home.ui

import java.io.File

//kt语音默认是final修饰的，不可以被继承，区别于java的  如果想要继承一个类，就要先用open关键字修饰
open  class Persion(val name:String) {

    open fun showName() = "父类的名字是【${name}】"

    open fun println(){
        println("=====打印出来："+showName())
    }
    fun sunUserFa(){
        println("子类调用了父类的方法")
    }
}

class Student(val stName:String):Persion("张飞") {
    override fun showName() = "子类的名字是【${stName}】"

     override fun println(){
        println("=====打印出来："+showName())
    }
}


fun main() {
  val persion :Persion =  Student("张小飞")
    persion.println()
    println(persion is Persion)
    println(persion is Student)
    println(persion is File)

    if (persion is Persion) {
        (persion as Persion).println()//子类重写了父类的方法，这时候走子类的打印方法
    }

    if (persion is Student) {
        (persion as Persion).println()
    }

    if (persion is Student) {
        (persion as Persion).sunUserFa()
    }

}



